import Hash.Hash;

import java.util.HashSet;
import java.util.Set;

public class Text {

    /**
     *  无重复字符的最长子串
     *
     * @param ss
     * @return
     */
    public int lengthOfLongestSubstring(String ss) {
        char[] s = ss.toCharArray();
        int[] hash = new int[128];
        int left = 0;
        int right = 0;
        int ret = 0;
        while(right < ss.length()){
            hash[s[right]]++;
            while (hash[s[right]] > 1){
                hash[s[left++]]--;
            }
            ret = Math.max(ret,right - left + 1);
            right++;
        }
        return ret;
    }


    /**
     * 长度最小的子数组
     * 时间复杂度O(2N) => O(N)
     * @param target
     * @param nums
     * @return
     */

    public int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = left;
        int sum = 0;
        int len = Integer.MAX_VALUE;
        while (right < nums.length){
            sum += nums[right];
            while (sum >= target){
                len = Math.min(len,right - left + 1);
                sum -= nums[left++];
            }
            right++;
        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }

    public static void main(String[] args) {

    }
}
